<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head th:include="/common/inc::header"/>
<body>
<table class="layui-table" id="grid" lay-filter="grid">
</table>
<script th:replace="/common/inc::incJs"></script>
<style type="text/css">
    .layui-table-cell {
        height: auto !important;
        white-space: normal;
    }
</style>
<script>
    var tableIns;

    $(function () {
        tableIns = createTable({
            url: 'list',
            cols: [[
                {field: 'shareRule', title: '分享页面规则', width: 400}, {
                    field: 'withdrawRule',
                    title: '提现页面规则',
                    width: 400
                },{
                    field: 'invoiceRule',
                    title: '发票提醒文案',
                    width: 200
                },{
                    field: 'joinVipRule',
                    title: '加入会员页面文案',
                    width: 300
                }, {
                    title: '操作',
                    width: 200,
                    align: 'center',
                    toolbar: '#opbar'
                }
            ]]
        })
    });

    layui.table.on('tool(grid)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值
        var tr = obj.tr; //获得当前行 tr 的DOM对象02\
        if (layEvent === 'del') { //删除
            delRecord("/backend/security/copywritingRules/del", obj)
        } else if (layEvent === 'change') { //删除
            changeStatus(data.id, data.status);
        } else if (layEvent === 'edit') { //编辑
            openDialog({
                url: "/backend/security/copywritingRules/detail?id=" + data.id,
                area: ["70%", "85%"],
                btn: ["保存", "取消"]
            });
        }
    });

    //变更标签状态
    function changeStatus(id, status) {
        if (status == "0") {
            $.post('/backend/security/copywritingRules/update', {id: id, status: 1}, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    }
                    else {
                        layer.msg("下架成功");
                        tableIns.reload();
                    }
                }
            )
        } else if (status = "1") {
            $.post('/backend/security/copywritingRules/update', {id: id, status: 0}, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    }
                    else {
                        layer.msg("上架成功");
                        tableIns.reload();
                    }
                }
            )
        }
    }

    layui.form.on('submit(addBtn)', function () {
        openDialog({
            url: "/backend/security/copywritingRules/detail",
            btn: ["保存", "取消"],
            area: ["70%", "75%"]
        });
        return false;
    });

    layui.form.on('submit(searchBtn)', function (data) {
        tableIns.reload({
            where: data.field
        });
        return false;
    });
</script>
<script type="text/html" id="opbar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
</script>
</body>
</html>
